﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FDSimpleModelGenerator.Common
{
    /// <summary>
    /// 缓存接口
    /// </summary>
    public interface ICache
    {
        /// <summary>
        /// 获取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">键</param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 获取，不存在则设置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">键值</param>
        /// <param name="addIfNotExists">不存在则设置委托</param>
        /// <param name="expires">过期时间</param>
        /// <returns></returns>
        T Get<T>(string key, Func<T> addIfNotExists, TimeSpan expires);

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="expires">过期时间</param>
        /// <returns></returns>
        bool Set<T>(string key, T value, TimeSpan expires);

    }
}
